﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS.AdminCP
{
    public partial class ListAlbum : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gvAlbum.DataSource = new cmsAlbumBL().SelectAll();
                gvAlbum.DataBind();
            }
        }

        protected void gvAlbum_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
        {
            int AlbumID = int.Parse(e.EditingKeyValue.ToString());
            Response.Redirect("Default.aspx?Page=Album&AlbumID=" + AlbumID.ToString());
        }

        public string TypeX(object e)
        {
            string s = "Album Ảnh";
            try
            {
                bool type = bool.Parse(e.ToString());
                if (type == true)
                    s = "Album Ảnh";
                else
                    s = "Album video";
            }
            catch (Exception)
            {
                
                throw;
            }
            return s;

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("/AdminCP/Album.aspx");
        }
        protected void gvAlbum_SelectedIndexChanged(object sender, EventArgs e)
        {
            int AlbumID = int.Parse(gvAlbum.DataKeys[gvAlbum.SelectedIndex].Value.ToString());
            Response.Redirect("/AdminCP/Album.aspx?AlbumID=" + AlbumID.ToString());
        }

        protected void gvAlbum_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int PLID = Convert.ToInt32(gvAlbum.DataKeys[e.RowIndex].Value);
            new cmsAlbumBL().Delete(new cmsAlbumDO { AlbumID = PLID });
            // new cmsImagesBL().DeleteByalbum(PLID);
            Functions.Alert("Xóa thành công", "/AdminCP/ListAlbum.aspx");
        }
    }
}